<!--
  -    Copyright (c) 2018-2025, lengleng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
  <div class="execution">
    <basic-container>
     <el-row style="margin-bottom:20px;font-size:15px">
        <el-col :span="6">是否开启公司简介审核: <el-switch active-color="#13ce66" inactive-color="#ff4949" size="small" @change="swichChenge"
        :active-value="1"
        :inactive-value="2"
         v-model="showSwich.companyAudit"> </el-switch></el-col>
      </el-row>
      <avue-crud
        ref="crud"
         v-model="form"
        :page="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
      >
        <!-- <template slot-scope="scope1" slot="menuForm">
            <div style="margin:0 auto">
                <el-button type="primary" @click="through">通过</el-button>
                <el-button type="danger" @click="noThrough">不通过</el-button>
            </div>

        </template> -->
        <template slot-scope="scope" slot="menu">
            <el-button type="text" @click="through(scope)">通过</el-button>
            <el-button type="text" @click="noThrough(scope)">不通过</el-button>
        </template>

      </avue-crud>

      <!---->
      <!-- <el-dialog title="审核" :visible.sync="auditVisible">
            <avue-form ref="form" v-model="obj0" :option="option0">
                <template slot="menuForm">
                    <el-button  type="primary" @click="handleSubmit">提 交</el-button>
                    <el-button  @click="handleEmpty">清 空</el-button>
                </template>
            </avue-form>
      </el-dialog> -->
    </basic-container>
  </div>
</template>

<script>
import { fetchList, getObj, addObj, putObj, delObj } from "@/api/circlecompany";
import { tableOption } from "@/const/crud/circlecompany";
import { mapGetters } from "vuex";

export default {
  name: "circlecompany",
  data() {
    return {
      showSwich:{},
      // companyAudit:2,
        form:{},
        obj0:{},
        option0:{
            //  detail:true,
          emptyBtn:false,
          submitBtn:false,
          column: [{
            label: "用户名",
            prop: "name",
            rules: [{
                required: true,
                message: "请输入用户名",
                trigger: "blur",

            }]
          }]
        },

      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,

      auditVisible:false,
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        addBtn: this.vaildData(
          this.permissions.circleCompany_circlecompany_add,
          false
        ),
        delBtn: this.vaildData(
          this.permissions.circleCompany_circlecompany_del,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.circleCompany_circlecompany_edit,
          false
        )
      };
    }
  },
  mounted() {
    var vm = this
      axios.get('/auditConfiguration/auditConfiguration').then(r=>{

        if (r.data.data!=null){
          vm.showSwich = r.data.data;
        }
      /* if(vm.showSwich.companyAudit == 1){
        vm.companyAudit == true;
      }
      if(vm.showSwich.companyAudit == 2){
        vm.companyAudit == false;
      } */
    })

  },
  methods: {
    swichChenge(e){
      var vm = this
      console.log(e)
      if(e == 1){
        axios.post('/auditConfiguration/updateAudit', vm.showSwich).then(r=>{

        })
      }
      if(e == 2){
         console.log('222',vm.showSwich.companyAudit)
        axios.post('/auditConfiguration/updateAudit',vm.showSwich).then(r=>{
        })
      }
    },

    through(data) {
      console.log(data.row.id);
      let vm = this;
      this.$confirm("是否通过审核", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        data.row.display = 1
        putObj(data.row)
          .then(r => {
            vm.$message.success("审核成功");
            vm.getList(vm.page);
          })
          .catch(() => {
          });
      })
    },
    noThrough(data) {
      console.log(data.row.id);
      let vm = this;
      this.$confirm("是否不通过审核", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        data.row.display = 2
        putObj(data.row)
          .then(r => {
            vm.$message.success("审核成功");
            vm.getList(vm.page);
          })
          .catch((r) => {
            console.log(r);
          });
      })
    },
    /*  through(data, index, done, loading){
          console.log(data.row.id);
          this.$confirm("是否通过审核", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        }).then(function(){
            data.row.display = 1
            putObj(data.row)
            .then(data => {

            this.$message.success("审核成功");
            done();
            this.getList(this.page);
            })
            .catch(() => {
                loading();
            });
        })
      },
      noThrough(data, index, done, loading){
          console.log(data.row.id);
          this.$confirm("是否不通过审核", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        }).then(function(){
            data.row.display = 2
            putObj(data.row)
            .then(data => {

            this.$message.success("审核成功");
            done();
            this.getList(this.page);
            })
            .catch(() => {
                loading();
            });
        })
      },*/

       /* handleEmpty(){
        this.$refs.form.resetForm();
      }, */
     /*  handleSubmit(){

        this.$refs.form.validate((vaild,done)=>{
          if(vaild){
            this.$message.success(JSON.stringify(this.obj0));
            setTimeout(()=>{
              done()
            },2000)
          }
        })
      }, */
    getList(page, params) {
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.page.total = response.data.data.total;
          let originData = response.data.data.records;
          // originData.map(r=>{
          //     r.address = JSON.parse(r.address)
          //     r.address = r.address.name
          //     // var pic = JSON.parse(r.pic)
          //     // console.log(pic)
          //     // let picArr = [];
          //     // pic.map(res=>{
          //     //     picArr.push(res.url);
          //     // })
          //     // r.pic = picArr.join(',')
          //     // console.log(r.pic)
          //     return r;
          // })
          originData.map(r => {
            if (r.address) {
              let addr = JSON.parse(r.address);
              r.address = addr.name;
            }
            let picArr = [];
            if (r.pic) {
              let picObj = JSON.parse(r.pic);
              picObj.map(res => {
                picArr.push(res.url);
              });
              r.pic = picArr.join(",");
            }
            return r;
          });
          this.tableData = originData;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    rowDel: function(row, index) {
      this.$confirm("是否确认删除ID为" + row.id, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return delObj(row.id);
        })
        .then(data => {
          this.$message.success("删除成功");
          this.getList(this.page);
        });
    },
    handleUpdate: function(row, index, done, loading) {
      putObj(row)
        .then(data => {

          this.$message.success("修改成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    handleSave: function(row, done, loading) {
      addObj(row)
        .then(data => {
          this.$message.success("添加成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getList(this.page, form);
      done();
    },
    refreshChange() {
      this.getList(this.page);
    },
  }
};
</script>
